//
//  FSCHomeworkListViewModel.swift
//  FamiliesSchoolConnection
//
//  Created by 花花蔡 on 2016/12/29.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

import UIKit
import SVProgressHUD

class FSCHomeworkListViewModel {

    var homeworkModelArr:[FSCHomeworkModel] = []
    
    
    func loadData( finish:@escaping (_ isOK:Bool)->() ) -> Void {
        
        SVProgressHUD.show()
        let urlStr = "ZH-schoolname-S-getHomeworkBase"
        let parm = ["key":userID,"id":"1"]
        
        FSCNetworkTools.shared.request(url: urlStr, parameters: parm) { [weak self] (data, error) in
            
            guard let data = data as? NSDictionary else {
                SVProgressHUD.showInfo(withStatus: "加载失败")
                return
            }
            SVProgressHUD.dismiss()
            //            print(data,"----")
            
            switch data["result"] as! Int {
            case 0:
                guard let arr = data["data"] as? [NSDictionary] else {
                    return
                }
                
                for dict in arr {
                    let model = FSCHomeworkModel(dict:dict)
                    self?.homeworkModelArr.append(model)
                }
                finish(true)
            case 1:
                SVProgressHUD.showInfo(withStatus: "加载失败")
                finish(false)
            default:
                break
            }
        }
        
    }

    
}
